<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>添加试题</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layuimoduls/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuimoduls/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <blockquote class="layui-elem-quote layui-text">
            如果为非选择题，选项可不填，如果为选择题，必须填写选项，暂时不支持试卷自动导入。
        </blockquote>

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>添加试题</legend>
        </fieldset>

        <form class="layui-form" id="form">
            <div class="layui-form-item">
                <label class="layui-form-label">试题类型</label>
<!--                1 选择题 2 填空题 3 简答题-->
                <div class="layui-input-block">
                    <input type="radio" name="type" value="单选题" title="单选题" checked="">
                    <input type="radio" name="type" value="填空题" title="填空题">
                    <input type="radio" name="type" value="简答题" title="简答题">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">试题题干</label>
                <div class="layui-input-block">
                    <input type="text" name="stem"   lay-reqtext="题干是必填项" placeholder="请输入题干" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">选项A</label>
                <div class="layui-input-block">
                    <input type="text" name="opta"  placeholder="请输入选项A" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">选项B</label>
                <div class="layui-input-block">
                    <input type="text" name="optb"  placeholder="请输入选项B" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">选项C</label>
                <div class="layui-input-block">
                    <input type="text" name="optc"  placeholder="请输入选项C" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">选项D</label>
                <div class="layui-input-block">
                    <input type="text" name="optd"  placeholder="请输入选项D" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">答案</label>
                <div class="layui-input-block">
                    <input type="text" name="right"  placeholder="请输入答案" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">分数</label>
                <div class="layui-input-block">
                    <input type="text" name="score"  placeholder="请输入分数" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">解析</label>
                <div class="layui-input-block">
                    <input type="text" name="analyse"  placeholder="请输入解析" class="layui-input">
                </div>
            </div>


<!--            <div class="layui-form-item">-->
<!--                <label class="layui-form-label">时间限制</label>-->
<!--                <div class="layui-input-inline">-->
<!--                    <input type="text" class="layui-input" id="test10" placeholder=" - ">-->
<!--                </div>-->
<!--            </div>-->

            <div class="layui-form-item">
                <label class="layui-form-label">选择科目</label>
                <div class="layui-input-inline">
                    <select name="subjectname">
                        <option value="">选择科目</option>
                        <option  name="subjectname" value="数据结构" selected="">数据结构</option>
                        <option name="subjectname" value="java基础">java基础</option>
                        <option name="subjectname" value="javaweb">javaweb</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" lay-submit="" lay-filter="demo1">立即添加</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="/layuimoduls/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/jquery/jquery-3.6.0.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script  th:inline="none">
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //日期时间范围
        laydate.render({
            elem: '#test10',
            type: 'datetime',
            range: true
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            var data = JSON.stringify(data.field)
            layer.alert(data)
            $.post({
                url: "/insertQuestion",
                data: data,
                type: 'post',
                contentType: 'application/json;charset=utf-8',
                dataType: 'json',
                success: function (response) {
                    if (response.success) {
                        layer.msg(response.msg)
                        parent.location.reload(); //刷新父页面
                    } else {
                        layer.msg(response.msg)
                    }
                }
            })
        });

    });
</script>

</body>
</html>